package com.qinggeng.project.tool.third.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.tool.third.domain.SysThird;
import com.qinggeng.project.tool.third.service.ISysThirdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 第三方登录Controller
 *
 * @author qinggeng
 * @date 2020-03-13
 */
@RestController
@RequestMapping("/tool/third")
public class SysThirdController extends BaseController
{
    @Autowired
    private ISysThirdService sysThirdService;

    /**
     * 查询第三方登录列表
     */
    @PreAuthorize("@ss.hasPermi('tool:third:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysThird sysThird)
    {
        startPage();
        List<SysThird> list = sysThirdService.selectSysThirdList(sysThird);
        return getDataTable(list);
    }

    /**
     * 导出第三方登录列表
     */
    @PreAuthorize("@ss.hasPermi('tool:third:export')")
    @Log(title = "第三方登录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysThird sysThird)
    {
        List<SysThird> list = sysThirdService.selectSysThirdList(sysThird);
        ExcelUtil<SysThird> util = new ExcelUtil<SysThird>(SysThird.class);
        return util.exportExcel(list, "third");
    }

    /**
     * 获取第三方登录详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:third:query')")
    @GetMapping(value = "/{thirdId}")
    public AjaxResult getInfo(@PathVariable("thirdId") Long thirdId)
    {
        return AjaxResult.success(sysThirdService.selectSysThirdById(thirdId));
    }

    /**
     * 新增第三方登录
     */
    @PreAuthorize("@ss.hasPermi('tool:third:add')")
    @Log(title = "第三方登录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysThird sysThird)
    {
        return toAjax(sysThirdService.insertSysThird(sysThird));
    }

    /**
     * 修改第三方登录
     */
    @PreAuthorize("@ss.hasPermi('tool:third:edit')")
    @Log(title = "第三方登录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysThird sysThird)
    {
        return toAjax(sysThirdService.updateSysThird(sysThird));
    }

    /**
     * 删除第三方登录
     */
    @PreAuthorize("@ss.hasPermi('tool:third:remove')")
    @Log(title = "第三方登录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{thirdIds}")
    public AjaxResult remove(@PathVariable Long[] thirdIds)
    {
        return toAjax(sysThirdService.deleteSysThirdByIds(thirdIds));
    }
}
